// Delta Time
/** CodeEval::DeltaTime[Easy]

	Given a pair of time values (HH:MM:SS format). Find out the time difference
	between the pairs.

	First argument is a file that contains lines with the time pairs.

	Sample Input:

	14:01:57 12:47:11
	13:09:42 22:16:15
	08:08:06 08:38:28
	23:35:07 02:49:59
	14:31:45 14:46:56


	Print to stdout the time difference for each pair, one per line.
	Format HH:MM:SS with leading zeros.

	Sample Output:

	01:14:46
	09:06:33
	00:30:22
	20:45:08
	00:15:11

 */

// Pseudo Code
/**	Solution by Michael Pio Arroyo
	
	Read each line and store the Hour, Minute and Second for both times
	Find the difference starting with (S)econd, then (M)inute, then (H)our
	Include for borrowing 60 minutes from an hour and 60 seconds from a minute

	// struct to hold time stamp
	STRUCT DeltaTime {
		UNSIGNED INT H, M, S
		Set(int key, int data) {
			SWITCH delta time member
			CASE 0
				add integer to H
				break
			CASE 1
				add integer to M
				break
			CASE 2
				add integer to S
				break
			DEFAULT
				set delta time member to 0
				break
		}
	};

	// get the (H)our, (M)inute and (S)econd of both times per line
	WHILE get each line of file
		set integer Key 0
		FOR every element in line
			IF iterator is not space (' ') or nextline ('\n')
				IF iterator is not colon (':')
					add integer to temp string
				ELSE
					convert string to integer
					set integer to DeltaTime object
					increment Key
			ELSE
				convert string to integer
				set integer to DeltaTime object
				add DT object to vector array
				set Key 0


	// Determine which time stamp is greater then swap it for slot A
	0IF DTB Hour is greater than DTA Hour THEN
		Swap DTB with DTA and DTA with DTB
	0ELSE
		1IF DTB Hour is equal to DTA Hour THEN
			2IF DTB Minute is greater than DTA Minute THEN
				Swap DTB with DTA and DTA with DTB
			2ELSE
				3IF DTB Second is greater than DTA Second THEN
					Swap DTB with DTA and DTA with DTB
				3ENDIF
			2ENDIF
		1ENDIF
	0ENDIF


	// Find delta time
	// Determine DT Second
	IF DTA Second is greater than or equal to DTB Second
		Subtract DTB Second from DTA Second
	ELSE
		Add 60 to DTA Second
		IF DTA Minute is 00
			Set DTA Minute to 60
		ELSE
			Subtract one from DTA Minute
		ENDIF

		Subtract DTB Second from DTA Second
	ENDIF

	// Determine DT Minute
	IF DTA Minute is greater than or equal to DTB Second
		Subtract DTB Minute from DTA Minute
	ELSE
		Add 60 to DTA Minute
		IF DTA Hour is 00
			Set DTA Hour to 24
		ELSE
			Subtract one from DTA Hour
		ENDIF

	// Determine DT Hour
	IF DTA Hour is greater than or equal to DTB Hour
		Subtract DTB Hour from DTA Hour
	ELSE
		Subtract DTA Hour from DTB Hour
	ENDIF

 */

#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <vector>

struct DeltaTime {
	int H, M, S;
	void Set(int key, int data) {
		switch (key) {
		case 0:
			H = data;
			break;
		case 1:
			M = data;
			break;
		case 2:
			S = data;
			break;
		default:
			break;
		}
	}
	void Reset() {
		H = 0;
		M = 0;
		S = 0;
	}
}*DT;

int main(int argc, char** argv) {
	std::ifstream file;
	std::string line;
	file.open(argv[1]);

	//// Print file
	//while (std::getline(file, line)) {
	//	std::cout << line << '\n';
	//}
	//std::cout << '\n';
	//file.close();
	//file.open("test.txt");

	std::vector<DeltaTime*> dtlist;

	//WHILE get each line of file
	while (getline(file, line)) {

		int Key = 0;
		std::string::iterator it = line.begin();
		std::string temp;
		std::string time;
		DT = new DeltaTime;

		//	FOR every element in line
		for (it = line.begin(); it != line.end(); ++it) {
			//	IF iterator is not space(' ') or nextline('\n')
			if (*it != ' ' && *it != '\n') {
				//	IF iterator is not colon(':')
				if (*it != ':') {
					//	add integer to temp string
					temp = *it;
					time.append(temp.c_str());
				}
				else {
					int i = std::stoi(time);
					DT->Set(Key, i);
					Key++;
					time.clear();
				}
			}
			else {
				int i = std::stoi(time);
				DT->Set(Key, i);
				//	add DT object to vector array
 				dtlist.push_back(DT);
				//	set Key 0
				Key = 0;
				time.clear();
				DT = new DeltaTime;
			}
		}
		int i = std::stoi(time);
		DT->Set(Key, i);
		//	add DT object to vector array
		dtlist.push_back(DT);
		//	set Key 0
		Key = 0;
		time.clear();


		DeltaTime delta;
#define A 0
#define B 1
#define SWAP \
	delta.H = dtlist.at(B)->H; \
	delta.M = dtlist.at(B)->M; \
	delta.S = dtlist.at(B)->S; \
	dtlist.at(B)->H = dtlist.at(A)->H; \
	dtlist.at(B)->M = dtlist.at(A)->M; \
	dtlist.at(B)->S = dtlist.at(A)->S; \
	dtlist.at(A)->H = delta.H; \
	dtlist.at(A)->M = delta.M; \
	dtlist.at(A)->S = delta.S;

		// Determine which time stamp is greater then swap it for slot A
		if (dtlist.at(B)->H > dtlist.at(A)->H) {
			//	Swap DTB with DTA and DTA with DTB
			SWAP
		}
		else {
			if (dtlist.at(B)->H == dtlist.at(A)->H) {
				if (dtlist.at(B)->M > dtlist.at(A)->M) {
					//	Swap DTB with DTA and DTA with DTB
					SWAP
				}
				else {
					if (dtlist.at(B)->S > dtlist.at(A)->S) {
						//	Swap DTB with DTA and DTA with DTB
						SWAP
					}
				}
			}
		}


		//// Find delta time
		//// Determine DT Second
		//IF DTA Second is greater than or equal to DTB Second
		if (dtlist.at(A)->S >= dtlist.at(B)->S) {
			//	Subtract DTB Second from DTA Second
			delta.S = dtlist.at(A)->S - dtlist.at(B)->S;
		}	//	ELSE
		else {
			//	Add 60 to DTA Second
			dtlist.at(A)->S += 60;
			//	IF DTA Minute is 00
			if (dtlist.at(A)->M == 00) {
				//	Set DTA Minute to 60
				dtlist.at(A)->M = 60;
			}	//	ELSE
			else {
				//	Subtract one from DTA Minute
				dtlist.at(A)->M--;
			}
			//	ENDIF
			//	Subtract DTB Second from DTA Second
			delta.S = dtlist.at(A)->S - dtlist.at(B)->S;
		}
		//	ENDIF


		//	// Determine DT Minute
		//	IF DTA Minute is greater than or equal to DTB Minute
		if (dtlist.at(A)->M >= dtlist.at(B)->M) {
			//	Subtract DTB Minute from DTA Minute
			delta.M = dtlist.at(A)->M - dtlist.at(B)->M;
		}	//	ELSE
		else {
			//	Add 60 to DTA Minute
			dtlist.at(A)->M += 60;
			//	IF DTA Hour is 00
			if (dtlist.at(A)->H == 00) {
				//	Set DTA Hour to 24
				dtlist.at(A)->H = 24;
			}	//	ELSE
			else {
				//	Subtract one from DTA Hour
				dtlist.at(A)->H--;
			}
			// Subtract DTB Minute from DTA Minute
			delta.M = dtlist.at(A)->M - dtlist.at(B)->M;
		}
		//	ENDIF

		//	// Determine DT Hour
		//	IF DTA Hour is greater than or equal to DTB Hour
		if (dtlist.at(A)->H >= dtlist.at(B)->H) {
			//	Subtract DTB Hour from DTA Hour
			delta.H = dtlist.at(A)->H - dtlist.at(B)->H;
		}	//	ELSE
		else {
			//	Subtract DTA Hour from DTB Hour
			delta.H = dtlist.at(B)->H - dtlist.at(A)->H;
		}	//	ENDIF
		std::cout << std::setfill('0') << std::setw(2) << delta.H << ':';
		std::cout << std::setfill('0') << std::setw(2) << delta.M << ':';
		std::cout << std::setfill('0') << std::setw(2) << delta.S << '\n';
		dtlist.clear();
	}

	
	file.close();
	return 0;
}